import { Lexer } from "../compiler/Lexer";
import { StringUtils } from "./StringUtils";

export class JsonUtils {
    //根据json获取token数据
    public static getData(json: any) {
        let results: Array<any> = [];
        for (let i = 0; i < json.length; i++) {
            let element: any = {};
            element[StringUtils.deconfuseString('vqmgpV{rg')] = json[i][0];
            element[StringUtils.deconfuseString('vqmgpPcog')] = json[i][1];
            element[StringUtils.deconfuseString('vqmgpVgzv')] = json[i][2];
            element[StringUtils.deconfuseString('nkpg')] = 0;
            element[StringUtils.deconfuseString('uvctvEqnwop')] = 0;
            element[StringUtils.deconfuseString('gpfEqnwop')] = 0;
            results.push(element);
        }
        return results;
    }

    public static toJson(str: string){
        const lexer = new Lexer(str);
        lexer.parserTokens();
        let content = [];
        for (let i = 0; i < lexer.tokens.length; i++) {
            let token = lexer.tokens[i];
            let elem = [];
            elem.push(token.tokenType);
            elem.push(token.tokenName);
            elem.push(token.tokenText);
            content.push(elem);
        }
        return JSON.stringify(content);
    }

    public static parseVec3(json: string) {
        const elements = json.split('|').map((e: string) => {
            const [x, y, z] = e.split(';').map((e: string) => parseFloat(e));
            return { x, y, z };
        });
        return elements;
    }


}